<template>
  <div class="setPas-input">
    <setpas-back-btn>
      <div slot="set-title" class="login-title">设置密码</div>
      <div slot="border-bottom" class="border-bottom"></div>
    </setpas-back-btn>

    <el-form ref="setPasFormRef" :model="setPasForm" :rules="setPasFormRules">
      <!-- 手机号 -->
      <el-form-item class="setPas-input-phone" prop="password">
        <el-input v-model="setPasForm.password"></el-input>
      </el-form-item>

      <!-- 密码 -->
      <el-form-item class="setPas-input-verification" prop="repassword">
        <el-input v-model="setPasForm.repassword"> </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" class="btn" @click="finish">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import SetpasBackBtn from "./components/backButton";
export default {
  name: "SetPas",
  components: {
    SetpasBackBtn,
  },
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.setPasForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      setPasForm: {
        password: "",
        repassword: "",
      },
      setPasFormRules: {
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "长度在 3 到 15 个字符",
            trigger: "blur",
          },
        ],
        repassword: [
          { required: true, validator: validatePass2, trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    finish () {
       this.$refs.setPasFormRef.validate(async (vaid) => {
         if (!vaid) return;
          this.$router.push('/')
       })
    }
  }
};
</script>

<style lang="less" scoped>
.setPas-input {
  .setPas-input-phone {
    margin: 0.25rem 0.52rem 0 0.52rem;
  }
  .setPas-input-verification {
    margin: 0.25rem 0.52rem 0 0.52rem;
  }
  .btn {
    width: 1.85rem;
    height: 0.4rem;
    font-size: 0.15rem;
    color: #ffffff;
    text-align: center;
    margin-top: 0.35rem;
    margin-left: 0.95rem;
    background: #d20a0a;
  }
  .forgetpas {
    margin-left: 1.6rem;
  }
}
</style>
